﻿using System;
using System.IO;
using System.Text;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;
using System.Collections.Generic;


namespace EpisodeWizard.App.WizardPages
{
	public partial class WizardPageSelectFiles : CoreUI.WizardPage
	{
		public WizardPageSelectFiles()
		{
			InitializeComponent();
		}

		/// <summary>
		/// Add all the movie files from a folder
		/// </summary>
		private void btnSelectFolder_Click(object sender, EventArgs e)
		{
			CoreUI.SelectFolderDialog Dlg = new CoreUI.SelectFolderDialog();
			DialogResult Res = Dlg.ShowDialog();
			if (Res == DialogResult.OK)
			{
				Core.Program.GetInstance().AddFiles(Dlg.ReturnPath);
			}
		}

		/// <summary>
		/// Add all the specified files
		/// </summary>
		private void btnAddFiles_Click(object sender, EventArgs e)
		{
			List<string> Files = new List<string>();

			OpenFileDialog Dlg = new OpenFileDialog();
			Dlg.Multiselect = true;
			if (Dlg.ShowDialog() == DialogResult.OK)
			{
				foreach (string Filepath in Dlg.FileNames)
				{
					Files.Add(Filepath);
				}
			}

			Core.Program.GetInstance().AddFiles(Files);
		}

		/// <summary>
		/// Remove all the files from the list
		/// </summary>
		private void btnRemoveAllFiles_Click(object sender, EventArgs e)
		{
			Core.Program.GetInstance().RemoveAllFiles();
		}

		/// <summary>
		/// Check if the user can go on to the next page
		/// </summary>
		private void WizardPageSelectFiles_ValidatePage(ValidatePageEventArgs e)
		{
			if (Core.Program.GetInstance().EpisodeFiles.Count == 0)
			{
				MessageBox.Show("Please add some file first", "Cannot proceed", MessageBoxButtons.OK, MessageBoxIcon.Warning);
				e.Cancel = true;
			}
		}
	}
}
